package com.app.player;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.widget.ProgressBar;
import android.widget.Toast;

public class ServicoPlayer extends Service implements InterfaceMp3{

	
	private final ConexaoInterfaceMp3 conexao = new ConexaoInterfaceMp3();
	
	private PlayerMp3 player = new PlayerMp3();
	
	public class ConexaoInterfaceMp3 extends Binder{
		public InterfaceMp3 getService(){
			return ServicoPlayer.this;
		}
	}
	
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId){
		Toast.makeText(this, "Iniciando o Serviço",Toast.LENGTH_SHORT).show();
		return super.onStartCommand(intent, flags, startId);
	}
	
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return conexao;
	}
	
	@Override
	public void onDestroy(){
		System.out.println("Serviço destruido");
		player.fechar();
	}

	@Override
	public String getMusicaCorrente() {
		// TODO Auto-generated method stub
		return player.getMusicaTocando();
	}


	@Override
	public void parar() {
		player.parar();
	}

	@Override
	public int getDuracao() {
		return player.getDuracao();
	}

	@Override
	public int getPosicaoMusica() {
		// TODO Auto-generated method stub
		return player.getPosicaoMusica();
	}

	@Override
	public void destruirServico() {
		// TODO Auto-generated method stub
		this.onDestroy();
	}

	@Override
	public void passaMusica() {
		player.passaMusica();
	}

	@Override
	public boolean isTocando() {
		// TODO Auto-generated method stub
		return player.isTocando();
	}


	@Override
	public void iniciar(String mp3) {
		// TODO Auto-generated method stub
		player.iniciar(mp3);
	}


	@Override
	public void tocar() {
		// TODO Auto-generated method stub
		player.tocar();
	}


	@Override
	public void pausar() {
		// TODO Auto-generated method stub
		player.pausar();
	}


	@Override
	public void fechar() {
		// TODO Auto-generated method stub
		player.fechar();
	}


	@Override
	public void setPosicaoMusica(int posicao) {
		// TODO Auto-generated method stub
		player.setPosicaoMusica(posicao);
	}


	@Override
	public boolean getTerminou() {
		// TODO Auto-generated method stub
		return player.isTerminou();
	}
	
}
